package org.jeecg.demo.wx.convert;

import org.jeecg.demo.wx.entity.EScheduleUserCount;
import org.jeecg.demo.wx.enumeration.ScheduleStatusEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * 功能描述
 * map转换类
 *
 * @author: zgq
 * @date: 2024年03月10日 10:45
 */
public class EScheduleUserCount2MapConvert {


    public static Map<String, Object> convert(EScheduleUserCount eScheduleUserCount) {
        Map<String, Object> map = new HashMap<>();
        map.put(ScheduleStatusEnum.READ.getDesc(), eScheduleUserCount.getReadCount());
        map.put(ScheduleStatusEnum.UNREAD.getDesc(), eScheduleUserCount.getUnreadCount());
        map.put(ScheduleStatusEnum.FINISHED.getDesc(), eScheduleUserCount.getCompletedCount());
        map.put(ScheduleStatusEnum.UNDO.getDesc(), eScheduleUserCount.getUncompletedCount());
        return map;
    }

    public static EScheduleUserCount convert(Map<String, Object> map) {
        int readCount = (Integer) map.getOrDefault(ScheduleStatusEnum.READ.getDesc(), 0);
        int unreadCount = (Integer) map.getOrDefault(ScheduleStatusEnum.UNREAD.getDesc(), 0);
        int completedCount = (Integer) map.getOrDefault(ScheduleStatusEnum.FINISHED.getDesc(), 0);
        int uncompletedCount = (Integer) map.getOrDefault(ScheduleStatusEnum.UNDO.getDesc(), 0);

        return EScheduleUserCount.builder()
                .readCount(readCount).unreadCount(unreadCount)
                .uncompletedCount(completedCount).uncompletedCount(uncompletedCount)
                .build();
    }
}


